mod client;
mod config;
mod kenerl;

pub use client::*;
pub use config::*;
pub use kenerl::*;

#[cfg(test)]
mod tests {
    use std::future::Future;

    use talktive::{
        TalkTiveBuilder, TalkTiveConfig, TalktiveKenerl, Tool, ToolCollectionBuilder, ToolOutput,
        ToolParm, ToolSig, ToolSigParameter,
    };

    use super::*;
    pub struct TestTool {}

    #[async_trait::async_trait]
    impl Tool for TestTool {
        fn name(&self) -> &'static str {
            "DocumentSearcher"
        }
        fn new() -> Self
        where
            Self: Sized,
        {
            Self {}
        }
        fn sig(&self) -> talktive::ToolSig {
            ToolSig::new("DocumentSearcher".into(), "根据提示词搜索文档".into()).add_parameter(
                ToolSigParameter::new(
                    "keyword".into(),
                    "搜索文档的关键词".into(),
                    true,
                    talktive::ToolSigParameterType::String,
                ),
            )
        }
        async fn run(&self, parm: ToolParm) -> anyhow::Result<ToolOutput> {
            println!("function called with parm : {:?}", parm);
            unimplemented!()
        }
    }
    #[tokio::test]
    async fn it_works() {
        let talktive_config = TalkTiveConfig::default();
        let func = ToolCollectionBuilder::new().add::<TestTool>();
        let mut talktive = TalkTiveBuilder::<kenerl::ChatGLMRemote>::new_load_kenerl_config(
            "chatglm.config.yaml",
            talktive_config,
        )
        .unwrap()
        .with_tools(func)
        .build();
        talktive
            .history
            .push_merge::<<kenerl::ChatGLMRemote as TalktiveKenerl>::HistoryEncoder>(
                talktive::Message::System("你是一个成熟的AI了，应该学会自己搜索文档。".into()),
            )
            .unwrap();
        let res = talktive
            .generate(talktive::Message::User(
                "帮我在文档中搜索一下这个词：hello".into(),
            ))
            .await
            .unwrap();
        println!("{:?}", res);
    }
}
